/**
 *
 */
package com.py.credit.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.py.credit.common.logs.ExceptionLogger;
import com.py.credit.common.rest.RestServiceResult;
import com.py.credit.entity.Column;
import com.py.credit.entity.Dept;
import com.py.credit.entity.StatisticsResult;
import com.py.credit.entity.SysUser;
import com.py.credit.entity.Table;
import com.py.credit.entity.TableResult;
import com.py.credit.entity.common.OptionalColumn;
import com.py.credit.entity.enums.AdHocQueriesTableFieldEnum;
import com.py.credit.entity.enums.ResourceTableFieldsEnum;
import com.py.credit.entity.enums.SgsCfExportEnum;
import com.py.credit.entity.enums.SgsXkExportEnum;
import com.py.credit.service.ColumnService;
import com.py.credit.service.RemoteBaseService;
import com.py.credit.service.TableService;
import com.py.credit.utils.ExcelUtil;
import com.py.credit.utils.MapCache;
import com.py.framework.core.annotation.IgnoreAuthority;
import com.py.framework.core.common.Page;
import com.py.framework.core.helper.HttpServletHelper;

/**
 * @author dd
 */
@RestController
@RequestMapping(value = "/resourceSearch")
public class ResouceSearchController {
	@Autowired
	private TableService tableService;

	@Autowired
	private ColumnService columnService;

	@Autowired
	private RemoteBaseService remoteBaseService;

	private final static String FRONT_TABLE_ID = "resourceSeaarch";

	/**
	 * @api {get} /resourceSearch/getTableList.json 资源列表
	 * @apiName getTableList
	 * @apiVersion 0.0.1
	 * @apiGroup 信息资源查询
	 * @apiParam {String} kId 数据库id (必需)
	 * @apiParam {String} condition 搜索条件 (可选)
	 * @apiParam {int} limit 每页展示条数 (必需)
	 * @apiParam {int} page 当前页数 (必需)
	 * @apiParamExample {json} 请求参数示例
	 *                  {"kId":"100000","limit":10,"page":1,"deptId":1,"condition":[{"colNameCN":"信息资源名称","colNameEN":"resource_title","type":"varchar","fuzzy":true,"value":"欠缴电费信息"},{"colNameCN":"维护时间","colNameEN":"update_time","type":"timestamp","fuzzy":false,"value":["2018-05-28","2018-06-26"]}]}
	 * @apiSuccess {String} code 状态码:1 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {Object[]} data 结果集
	 * @apiSuccessExample {json}成功返回结果:
	 *                    {"code":0,"msg":null,"count":1,"data":[{"tableId":200249,"deptId":1,"kId":100000,"resource_id":"10000060873","resource_title":"欠缴电费信息","sharing_type":"P","update_frequency":"W","management_style":"A","maintainer":"superadmin","update_time":1523844712000}]}
	 */

	@RequestMapping(value = "/getTableList.json")
	public RestServiceResult<List<Map<String, Object>>> getTableList(
			@RequestParam(value = "kId", defaultValue = "", required = true) String kId,
			@RequestParam(value = "deptId", defaultValue = "", required = true) String deptId,
			@RequestParam(value = "condition", defaultValue = "", required = true) String condition, Page page,
			HttpServletRequest request) {

		RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));

		String[] configColumns = null;

		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {

			SysUser userInfo = user.getData();

			if (null != userInfo) {

				configColumns = (String[]) MapCache.get(userInfo.getId() + "_" + FRONT_TABLE_ID);
			} else {

				ExceptionLogger.error("ResouceSearchController#getTableList", "未获取到当前用户信息！");
			}

		} else {

			ExceptionLogger.error("ResouceSearchController#getTableList", "未获取到当前用户信息！");
		}

		List<String> showColumns = (configColumns == null || configColumns.length == 0)
				? ResourceTableFieldsEnum.getDefaultShowColumnEN()
				: Arrays.asList(configColumns);

		String[] additionalColumns = { "tableId", "deptId", "kId" };

		List<Map<String, Object>> tableList = tableService.getByConditionForPage(kId, deptId, "P", showColumns,
				additionalColumns, condition, page);

		return new RestServiceResult<List<Map<String, Object>>>(page.getTotalCount(), tableList);

	}

	/**
	 * @api {post} /resourceSearch/addShowColunms.json 缓存资源查詢結果展示列
	 * @apiName addShowColunms
	 * @apiVersion 0.0.1
	 * @apiGroup 信息资源查询
	 * @apiParam {String[]} columns 列名 (必需)
	 * @apiParam {String} tableName 表名 (必需)
	 * @apiSuccess {String} code 状态码:1 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {String} data 结果集
	 * @apiSuccessExample {json} 成功返回结果 {"code":0,"msg":null,"count":1,"data":null}
	 */

	@RequestMapping(value = "/addShowColunms.json")
	public RestServiceResult<String> addShowColunms(@RequestParam(value = "columns", required = true) String[] columns,
			@RequestParam(value = "tableName", required = true) String tableName, HttpServletRequest request) {

		RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));

		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {

			SysUser userInfo = user.getData();

			if (null != userInfo) {

				MapCache.set(userInfo.getId() + "_" + tableName, columns);
			} else {

				ExceptionLogger.error("CategoryController#addShowColunms", "未获取到当前用户信息！");
			}

		} else {

			ExceptionLogger.error("AdHocQueriesController#addShowColunms", "未获取到当前用户信息！");
		}

		return new RestServiceResult<String>();
	}

	/**
	 * @api {get} /resourceSearch/addResourceShowColunms.json 缓存资源列表展示列
	 * @apiName addResourceShowColunms
	 * @apiVersion 0.0.1
	 * @apiGroup 信息资源查询
	 * @apiParam {String[]} columns 列名 (必需)
	 * @apiSuccess {String} code 状态码:1 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {String} data 结果集
	 * @apiSuccessExample {json} 成功返回结果 {"code":0,"msg":null,"count":1,"data":null}
	 */
	@RequestMapping(value = "/addResourceShowColunms.json")
	public RestServiceResult<String> addShowColunms(@RequestParam(value = "columns", required = true) String[] columns,
			HttpServletRequest request) {

		RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));

		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {

			SysUser userInfo = user.getData();

			if (null != userInfo) {

				MapCache.set(userInfo.getId() + "_" + FRONT_TABLE_ID, columns);
			} else {

				ExceptionLogger.error("CategoryController#addResourceShowColunms", "未获取到当前用户信息！");
			}

		} else {

			ExceptionLogger.error("AdHocQueriesController#addResourceShowColunms", "未获取到当前用户信息！");
		}

		return new RestServiceResult<String>();
	}

	/**
	 * @api {get} /resourceSearch/selectRecord.json 资源查询结果列表
	 * @apiName selectRecord
	 * @apiVersion 0.0.1
	 * @apiGroup 信息资源查询
	 * @apiParam {String} tableName 表名称 (必需)
	 * @apiParam {int} tableId 表编码 (必需)
	 * @apiParam {String} condition 搜索条件 (可选)
	 * @apiParam {int} limit 每页展示条数 (必需)
	 * @apiParam {int} page 当前页数 (必需)
	 * @apiParamExample {json} 请求参数示例
	 *                  {"tableId":200249,"tableName":"t_10000060873","limit":10,"page":1,"condition":[{"colNameCN":"企业名称","colNameEN":"A000001","type":"varchar","fuzzy":true,"value":"企业"},{"colNameCN":"欠费时间","colNameEN":"JG_GGSY_QJDF_QJSJ","type":"timestamp","fuzzy":false,"value":["2018-05-10","2018-06-20"]}]}
	 * @apiSuccess {String} code 状态码:1 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {Object[]} data 结果集
	 * @apiSuccessExample {json}成功返回结果:
	 *                    {"code":0,"msg":null,"count":47,"data":[{"JG_GGSY_QJDF_JE":"10000","JG_GGSY_QJDF_BJRQ":1524543132000,"A000001":"企业1","A000002":"TY123456789","A000003":"GS12345679","A000004":"ZZ12345679","JG_GGSY_QJDF_QJSD":1524456732000,"JG_GGSY_QJDF_ZT":"已经补交","A000005":"SW12345679"},{"JG_GGSY_QJDF_JE":"10000","JG_GGSY_QJDF_BJRQ":1524543132000,"A000001":"企业3","A000002":"TY12345671","A000003":"GS1234561","A000004":"ZZ123451","JG_GGSY_QJDF_QJSD":1524456732000,"JG_GGSY_QJDF_ZT":"已经补交","A000005":"SW123451"},{"JG_GGSY_QJDF_JE":"10000","JG_GGSY_QJDF_BJRQ":1524543132000,"A000001":"企业3","A000002":"TY12345672","A000003":"GS1234562","A000004":"ZZ123452","JG_GGSY_QJDF_QJSD":1524456732000,"JG_GGSY_QJDF_ZT":"已经补交","A000005":"SW123452"},{"JG_GGSY_QJDF_JE":"10000","JG_GGSY_QJDF_BJRQ":1524543132000,"A000001":"企业4","A000002":"TY12345673","A000003":"GS1234563","A000004":"ZZ123453","JG_GGSY_QJDF_QJSD":1524456732000,"JG_GGSY_QJDF_ZT":"已经补交","A000005":"SW123453"},{"JG_GGSY_QJDF_JE":"10000","JG_GGSY_QJDF_BJRQ":1524543132000,"A000001":"企业5","A000002":"TY12345674","A000003":"GS1234564","A000004":"ZZ123454","JG_GGSY_QJDF_QJSD":1524456732000,"JG_GGSY_QJDF_ZT":"已经补交","A000005":"SW123454"},{"JG_GGSY_QJDF_JE":"10000","JG_GGSY_QJDF_BJRQ":1524543132000,"A000001":"企业6","A000002":"TY12345675","A000003":"GS1234565","A000004":"ZZ123455","JG_GGSY_QJDF_QJSD":1524456732000,"JG_GGSY_QJDF_ZT":"已经补交","A000005":"SW123455"},{"JG_GGSY_QJDF_JE":"10000","JG_GGSY_QJDF_BJRQ":1524543132000,"A000001":"企业6","A000002":"","A000003":"","A000004":"ZZ123455","JG_GGSY_QJDF_QJSD":1524456732000,"JG_GGSY_QJDF_ZT":"已经补交","A000005":"SW123455"},{"JG_GGSY_QJDF_JE":"10000","JG_GGSY_QJDF_BJRQ":1524543132000,"A000001":"企业6","A000002":"TY1234567","A000003":"GS1234565","A000004":"ZZ123455","JG_GGSY_QJDF_QJSD":1524456732000,"JG_GGSY_QJDF_ZT":"已经补交","A000005":"SW123455"},{"JG_GGSY_QJDF_JE":"10000","JG_GGSY_QJDF_BJRQ":1524543132000,"A000001":"企业7","A000002":"TY1234","A000003":"","A000004":"","JG_GGSY_QJDF_QJSD":1524456732000,"JG_GGSY_QJDF_ZT":"已经补交","A000005":""},{"JG_GGSY_QJDF_JE":"10000","JG_GGSY_QJDF_BJRQ":1524543132000,"A000001":"企业7","A000002":"","A000003":"TY1234","A000004":"TY12341","JG_GGSY_QJDF_QJSD":1524456732000,"JG_GGSY_QJDF_ZT":"已经补交","A000005":""}]}
	 */

	@RequestMapping(value = "/selectRecord.json")
	public RestServiceResult<List<Map<String, Object>>> selectRecord(
			@RequestParam(value = "tableName", defaultValue = "", required = true) String tableName,
			@RequestParam(value = "tableId", defaultValue = "", required = true) int tableId,
			@RequestParam(value = "deptId", defaultValue = "", required = true) String deptId,
			@RequestParam(value = "condition", defaultValue = "", required = true) String condition, Page page,
			HttpServletRequest request) {

		RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));

		String[] configColumns = null;

		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {

			SysUser userInfo = user.getData();

			if (null != userInfo) {

				configColumns = (String[]) MapCache.get(userInfo.getId() + "_" + tableName);
			} else {

				ExceptionLogger.error("ResouceSearchController#selectRecord", "未获取到当前用户信息！");
			}

		} else {

			ExceptionLogger.error("ResouceSearchController#selectRecord", "未获取到当前用户信息！");
		}

		List<String> showColumns = null;

		if (configColumns == null || configColumns.length == 0) {

			showColumns = columnService.getColumnENByTableId(tableId);
			// status非配置字段要显示这里加上
			showColumns.add("status");
			showColumns.add("record_id");

		} else {

			showColumns = Arrays.asList(configColumns);
		}

		List<Map<String, Object>> tableList = tableService.getRecordsByConditionForPage(null, tableName, deptId,
				showColumns, null, condition, page);

		return new RestServiceResult<List<Map<String, Object>>>(page.getTotalCount(), tableList);
	}

	/**
	 * @api {get} /resourceSearch/getOptionalColumns.json 获取资源列表普通搜索列和导出列
	 * @apiName getOptionalColumns
	 * @apiVersion 0.0.1
	 * @apiGroup 信息资源查询
	 * @apiParam {String} tableId 資源id (必需)
	 * @apiSuccess {String} colNameEN 列英文名
	 * @apiSuccess {String} colNameCN 列英中文名
	 * @apiSuccess {String} type 列类型
	 * @apiSuccess {String} defaultShow 是否默认显示
	 * @apiSuccess {String} widget 页面组件
	 * @apiSuccess {Boolean} fuzzy 是否支持模糊查询
	 * @apiSuccess {Boolean} searchIsShow 是否普通搜索列
	 * @apiSuccess {Object} widgetValue 列字典值
	 * @apiSuccessExample {json}成功返回结果:
	 *                    [{"colNameEN":"A000001","colNameCN":"企业名称","type":"varchar","defaultShow":true,"widget":"input","fuzzy":true,"widgetValue":null,"searchIsShow":true},{"colNameEN":"A000002","colNameCN":"统一社会信用代码","type":"varchar","defaultShow":true,"widget":"input","fuzzy":true,"widgetValue":null,"searchIsShow":true},{"colNameEN":"A000003","colNameCN":"工商登记码","type":"varchar","defaultShow":true,"widget":"input","fuzzy":true,"widgetValue":null,"searchIsShow":true},{"colNameEN":"A000004","colNameCN":"组织机构代码","type":"varchar","defaultShow":true,"widget":"input","fuzzy":true,"widgetValue":null,"searchIsShow":true},{"colNameEN":"A000005","colNameCN":"税务登记号","type":"varchar","defaultShow":true,"widget":"input","fuzzy":true,"widgetValue":null,"searchIsShow":true},{"colNameEN":"A000006","colNameCN":"注册地址","type":"varchar","defaultShow":true,"widget":"input","fuzzy":true,"widgetValue":null,"searchIsShow":true},{"colNameEN":"JG_GGSY_QJDF_SFDW","colNameCN":"收费单位名称","type":"varchar","defaultShow":true,"widget":"input","fuzzy":true,"widgetValue":null,"searchIsShow":true},{"colNameEN":"JG_GGSY_QJDF_JE","colNameCN":"欠费金额","type":"varchar","defaultShow":true,"widget":"input","fuzzy":true,"widgetValue":null,"searchIsShow":true},{"colNameEN":"JG_GGSY_QJDF_QJSD","colNameCN":"欠费所属时段","type":"timestamp","defaultShow":true,"widget":"input","fuzzy":false,"widgetValue":null,"searchIsShow":true},{"colNameEN":"JG_GGSY_QJDF_QJSJ","colNameCN":"欠费时间","type":"timestamp","defaultShow":true,"widget":"input","fuzzy":false,"widgetValue":null,"searchIsShow":true},{"colNameEN":"JG_GGSY_QJDF_TS","colNameCN":"拖欠天数","type":"varchar","defaultShow":true,"widget":"input","fuzzy":true,"widgetValue":null,"searchIsShow":true},{"colNameEN":"JG_GGSY_QJDF_BJRQ","colNameCN":"欠费补缴日期","type":"timestamp","defaultShow":true,"widget":"input","fuzzy":false,"widgetValue":null,"searchIsShow":true},{"colNameEN":"JG_GGSY_QJDF_ZT","colNameCN":"当前状态","type":"varchar","defaultShow":true,"widget":"input","fuzzy":true,"widgetValue":null,"searchIsShow":true},{"colNameEN":"JG_GGSY_QJSF_GXSJ","colNameCN":"数据更新时间","type":"timestamp","defaultShow":true,"widget":"input","fuzzy":false,"widgetValue":null,"searchIsShow":true},{"colNameEN":"JG_GGSY_QJDF_GXSJ","colNameCN":"备注","type":"varchar","defaultShow":true,"widget":"input","fuzzy":true,"widgetValue":null,"searchIsShow":true}]
	 */

	@RequestMapping(value = "/getOptionalColumns.json")
	public RestServiceResult<List<OptionalColumn>> getOptionalColumns(
			@RequestParam(value = "tableId", defaultValue = "", required = true) int tableId) {

		List<OptionalColumn> optionalColumnByTableId = columnService.getOptionalColumnByTableId(tableId);

		OptionalColumn ol = new OptionalColumn("status", "状态", "varchar", true, "select", false,
				new HashMap<String, String>() {
					private static final long serialVersionUID = -3470156310757484691L;
					{
						put("S", "待自动关联");
						put("E", "错误数据");
						put("T", "无法关联");
						put("A", "关联成功");
						// put("R", "重复数据");
						put("F", "信用修复成功");
					}
				}, false);

		optionalColumnByTableId.add(ol);

		return new RestServiceResult<List<OptionalColumn>>(optionalColumnByTableId);
	}

	/**
	 * @api {get} /resourceSearch/getAdvancedConditionColumns.json 获取资源列表高级搜索列
	 * @apiName getAdvancedConditionColumns
	 * @apiVersion 0.0.1
	 * @apiGroup 信息资源查询
	 * @apiParam {String} kId 数据库id (必需)
	 * @apiSuccess {String} colNameEN 列英文名
	 * @apiSuccess {String} colNameCN 列英中文名
	 * @apiSuccess {String} type 列类型
	 * @apiSuccess {String} defaultShow 是否默认显示
	 * @apiSuccess {String} widget 页面组件
	 * @apiSuccess {Boolean} fuzzy 是否支持模糊查询
	 * @apiSuccess {Boolean} searchIsShow 是否普通搜索列
	 * @apiSuccess {Object} widgetValue 列字典值
	 * @apiSuccessExample {json}成功返回结果:
	 *                    [{"colNameEN":"resource_title","colNameCN":"信息资源名称","type":"varchar","defaultShow":true,"widget":"input","fuzzy":true,"widgetValue":{},"searchIsShow":true},{"colNameEN":"sharing_type","colNameCN":"公开属性","type":"varchar","defaultShow":true,"widget":"select","fuzzy":false,"widgetValue":{"P":"社会公开","A":"授权查询","S":"政务共享"},"searchIsShow":true},{"colNameEN":"update_frequency","colNameCN":"更新频率","type":"varchar","defaultShow":true,"widget":"select","fuzzy":false,"widgetValue":{"Q":"每季度","S":"实时","D":"每日","W":"每周","Y":"每年","M":"每月"},"searchIsShow":true},{"colNameEN":"management_style","colNameCN":"管理方式","type":"varchar","defaultShow":true,"widget":"select","fuzzy":false,"widgetValue":{"A":"计算机处理","M":"手动"},"searchIsShow":true},{"colNameEN":"update_time","colNameCN":"维护时间","type":"timestamp","defaultShow":true,"widget":"","fuzzy":false,"widgetValue":{},"searchIsShow":false},{"colNameEN":"service_type","colNameCN":"服务类型","type":"varchar","defaultShow":false,"widget":"select","fuzzy":false,"widgetValue":{"D":"目录","I":"接口"},"searchIsShow":false}]
	 */

	@RequestMapping(value = "/getAdvancedConditionColumns.json")
	public RestServiceResult<List<OptionalColumn>> getAdvancedConditionColumns(
			@RequestParam(value = "tableId", defaultValue = "", required = true) int tableId) {

		List<OptionalColumn> optionalColumnByTableId = columnService.getOptionalColumnByTableId(tableId);

		OptionalColumn ol = new OptionalColumn("status", "状态", "varchar", true, "select", false,
				new HashMap<String, String>() {
					private static final long serialVersionUID = -3470156310757484691L;
					{
						put("S", "待关联");
						put("E", "错误数据");
						put("T", "无法关联");
						put("A", "关联成功");
						put("R", "重复数据");
						put("F", "信用修复");
					}
				}, false);

		optionalColumnByTableId.add(ol);

		return new RestServiceResult<List<OptionalColumn>>(optionalColumnByTableId);

	}

	/**
	 * @api {get} /resourceSearch/exportResouceSearchList.json 导出资源查询结果数据
	 * @apiName exportResouceSearchList
	 * @apiVersion 0.0.1
	 * @apiGroup 信息资源查询
	 * @apiParam {String} tableName 表名称 (必需)
	 * @apiParam {int} tableId 表编码 (必需)
	 * @apiParam {String} condition 搜索条件 (可选)
	 * @apiParam {int} limit 每页展示条数 (必需)
	 * @apiParam {int} page 当前页数 (必需)
	 * @apiParamExample {json} 请求参数示例
	 *                  {"tableId":200249,"tableName":"t_10000060873","limit":10,"page":1,"condition":[{"colNameCN":"企业名称","colNameEN":"A000001","type":"varchar","fuzzy":true,"value":"企业"},{"colNameCN":"欠费时间","colNameEN":"JG_GGSY_QJDF_QJSJ","type":"timestamp","fuzzy":false,"value":["2018-05-10","2018-06-20"]}]}
	 */
	@RequestMapping(value = "/exportResouceSearchList.json")
	public void exportResouceSearchList(
			@RequestParam(value = "tableName", defaultValue = "", required = true) String tableName,
			@RequestParam(value = "tableId", defaultValue = "", required = true) int tableId,
			@RequestParam(value = "deptId", defaultValue = "", required = true) String deptId,
			@RequestParam(value = "recordIds", defaultValue = "", required = true) List<String> recordIds,
			@RequestParam(value = "columnEN", defaultValue = "", required = true) String columnEN,
			@RequestParam(value = "condition", defaultValue = "", required = true) String condition, Page page,
			HttpServletResponse response) throws IOException {
		page.setLimit(100000);
		List<String> showColumns = JSONArray.parseArray(columnEN, String.class);
		;
		Table tableResult = tableService.queryCubeById(tableId);
		List<Map<String, Object>> tableList = tableService.getRecordsByConditionForPage(recordIds, tableName, deptId,
				showColumns, null, condition, page);
		List<OptionalColumn> optionalColumns = columnService.getOptionalColumnByTableId(tableId);
		ExcelUtil.downloadExcel(response, tableList, tableResult.getResourceTitle(), tableResult.getResourceTitle(),
				showColumns, optionalColumns);

	}

	@RequestMapping(value = "/getTableListForSearch.json")
	public RestServiceResult<List<Map<String, String>>> getTableListForSearch(
			@RequestParam(value = "deptid", defaultValue = "", required = true) List<String> deptId) {

		List<Map<String, String>> data = tableService.getTableListForSearch(deptId);

		return new RestServiceResult<List<Map<String, String>>>(data);
	}

	@RequestMapping(value = "/getStatistics.json")
	public RestServiceResult<List<StatisticsResult>> getStatistics(
			@RequestParam(value = "startTime", defaultValue = "", required = true) String startTime,
			@RequestParam(value = "endTime", defaultValue = "", required = true) String endTime,
			@RequestParam(value = "deptId", defaultValue = "", required = true) List<String> deptId,
			@RequestParam(value = "tableId", defaultValue = "", required = true) List<String> tableId) {

		List<StatisticsResult> data = tableService.getStatistics(startTime, endTime, deptId, tableId);

		return new RestServiceResult<List<StatisticsResult>>(data);
	}

	@RequestMapping(value = "/exportStatistics.json")
	public RestServiceResult<List<StatisticsResult>> exportStatistics(
			@RequestParam(value = "startTime", defaultValue = "", required = true) String startTime,
			@RequestParam(value = "endTime", defaultValue = "", required = true) String endTime,
			@RequestParam(value = "deptId", defaultValue = "", required = true) List<String> deptId,
			@RequestParam(value = "tableId", defaultValue = "", required = true) List<String> tableId,
			HttpServletResponse response) {

		List<StatisticsResult> data = tableService.getStatistics(startTime, endTime, deptId, tableId);
		tableService.exportStatistics(startTime, endTime, data, response);
		return new RestServiceResult<List<StatisticsResult>>(null);
	}

	@IgnoreAuthority
	@RequestMapping(value = "/getTableDatas.json")
	public RestServiceResult<List<StatisticsResult>> getTableDatas(
			@RequestParam(value = "startTime", defaultValue = "", required = true) String startTime,
			@RequestParam(value = "endTime", defaultValue = "", required = true) String endTime,
			@RequestParam(value = "deptId", defaultValue = "", required = true) String deptId,
			@RequestParam(value = "tableId", defaultValue = "", required = true) String tableId,
			HttpServletResponse response) {
		RestServiceResult<List<StatisticsResult>> result = new RestServiceResult<List<StatisticsResult>>();
		try {
			tableService.getTableDatas(startTime, endTime, deptId, tableId, response);
		} catch (Exception e) {
			result.setMsg(e.getMessage());
			return result;
		}

		return new RestServiceResult<List<StatisticsResult>>(null);
	}

	@IgnoreAuthority
	@RequestMapping(value = "/getSgsTotalList.json")
	public RestServiceResult<List<Map<String, Object>>> getSgsTotalList(
			@RequestParam(value = "condition", defaultValue = "", required = true) String condition,
			@RequestParam(value = "columnEN", defaultValue = "", required = true) String columnEN,
			@RequestParam(value = "type", defaultValue = "", required = true) String type,
			@RequestParam(value = "startTime", defaultValue = "", required = true) String startTime,
			@RequestParam(value = "jdrqStart", defaultValue = "", required = true) String jdrqStart,
			@RequestParam(value = "jdrqEnd", defaultValue = "", required = true) String jdrqEnd,
			@RequestParam(value = "endTime", defaultValue = "", required = true) String endTime,
			@RequestParam(value = "deptId", defaultValue = "", required = true) List<String> deptId, Page page,
			HttpServletResponse response) {
		RestServiceResult<List<Map<String, Object>>> result = new RestServiceResult<List<Map<String, Object>>>();
		try {

			List<String> columns = java.util.Arrays.asList(columnEN.split(","));
			List<String> showColumns = new ArrayList<String>();

			showColumns.add("OFFICE_NAME");
			showColumns.add("frcount");
			showColumns.add("zrrcount");

			List<Map<String, Object>> data = tableService.getSgsTotalByConditionForPage(columns, condition, type,
					deptId, response, startTime, endTime, page, jdrqStart, jdrqEnd);
			result.setData(data);
			result.setCount(page.getTotalCount());
		} catch (Exception e) {
			ExceptionLogger.error("ResouceSearchController#getSgsTotalList", "查询列表异常，请稍后再试！ERROR:" + e.getMessage(), e);
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("查询列表异常，请稍后再试");
			return result;
		}

		return result;
	}

	@IgnoreAuthority
	@RequestMapping(value = "/exportSgsTotal.json")
	public RestServiceResult<List<StatisticsResult>> exportSgsTotal(
			@RequestParam(value = "condition", defaultValue = "", required = true) String condition,
			@RequestParam(value = "columnEN", defaultValue = "", required = true) String columnEN,
			@RequestParam(value = "type", defaultValue = "", required = true) String type,
			@RequestParam(value = "startTime", defaultValue = "", required = true) String startTime,
			@RequestParam(value = "endTime", defaultValue = "", required = true) String endTime,
			@RequestParam(value = "jdrqStart", defaultValue = "", required = true) String jdrqStart,
			@RequestParam(value = "jdrqEnd", defaultValue = "", required = true) String jdrqEnd,
			@RequestParam(value = "deptId", defaultValue = "", required = true) List<String> deptId,
			HttpServletResponse response) {
		RestServiceResult<List<StatisticsResult>> result = new RestServiceResult<List<StatisticsResult>>();
		try {
			Page page = new Page();
			page.setLimit(500);
			List<String> columns = java.util.Arrays.asList(columnEN.split(","));
			List<String> showColumns = new ArrayList<String>();

			showColumns.add("OFFICE_NAME");
			showColumns.add("tcount");
			showColumns.add("frcount");
			showColumns.add("zrrcount");

			List<Map<String, Object>> data = tableService.getSgsTotalByConditionForPage(columns, condition, type,
					deptId, response, startTime, endTime, page, jdrqStart, jdrqEnd);
			List<OptionalColumn> OptionalColumns = new ArrayList<>();
			OptionalColumn optionalColumn = new OptionalColumn("OFFICE_NAME", "部门名称", "varchar", true, "input", false,
					new HashMap<String, String>(), false);
			OptionalColumns.add(optionalColumn);
			if (type.equals("许可")) {
				optionalColumn = new OptionalColumn("tcount", "行政许可数量", "number", true, "input", false,
						new HashMap<String, String>(), false);
			} else {
				optionalColumn = new OptionalColumn("tcount", "行政处罚数量", "number", true, "input", false,
						new HashMap<String, String>(), false);
			}
			OptionalColumns.add(optionalColumn);
			optionalColumn = new OptionalColumn("frcount", "法人数量", "number", true, "input", false,
					new HashMap<String, String>(), false);
			OptionalColumns.add(optionalColumn);
			optionalColumn = new OptionalColumn("zrrcount", "自然人数量", "number", true, "input", false,
					new HashMap<String, String>(), false);
			OptionalColumns.add(optionalColumn);
			ExcelUtil.downloadExcel(response, data, type, type, showColumns, OptionalColumns);
		} catch (Exception e) {
			ExceptionLogger.error("ResouceSearchController#exportSgsTotal", "导出异常，请稍后再试！ERROR:" + e.getMessage(), e);
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("导出异常，请稍后再试");
			return result;
		}

		return new RestServiceResult<List<StatisticsResult>>(null);
	}

	@IgnoreAuthority
	@RequestMapping(value = "/getSgsOptionalColumns.json")
	public RestServiceResult<List<OptionalColumn>> getSgsOptionalColumns(
			@RequestParam(value = "type", defaultValue = "", required = true) String type) {

		RestServiceResult<List<OptionalColumn>> result = new RestServiceResult<List<OptionalColumn>>();
		List<OptionalColumn> optionalColumnByTableId = new ArrayList<OptionalColumn>();
		try {

			if ("许可".equals(type)) {
				List<OptionalColumn> FrXk = columnService.getOptionalColumnByTableId(210000);
				List<OptionalColumn> ZrrXk = columnService.getOptionalColumnByTableId(210002);
				for (OptionalColumn fr : FrXk) {
					for (OptionalColumn zrr : ZrrXk) {
						if (fr.getColNameEN().equals(zrr.getColNameEN())) {
							optionalColumnByTableId.add(fr);
						}
					}
				}

			} else {
				List<OptionalColumn> FrCf = columnService.getOptionalColumnByTableId(210001);
				List<OptionalColumn> ZrrCf = columnService.getOptionalColumnByTableId(210003);
				for (OptionalColumn fr : FrCf) {
					for (OptionalColumn zrr : ZrrCf) {
						if (fr.getColNameEN().equals(zrr.getColNameEN())) {
							optionalColumnByTableId.add(fr);
						}
					}
				}
			}
			result.setData(optionalColumnByTableId);
			return result;
		} catch (Exception e) {
			ExceptionLogger.error("ResouceSearchController#getSgsOptionalColumns", "系统异常稍后再试！ERROR:" + e.getMessage(),
					e);
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("系统异常请稍后再试");
			return result;
		}
	}

	@IgnoreAuthority
	@RequestMapping(value = "/getSgsDept.json")
	public RestServiceResult<List<Map<String, Object>>> getSgsDept(String type) {
		RestServiceResult<List<Map<String, Object>>> result = new RestServiceResult<List<Map<String, Object>>>();
		try {
			List<Map<String, Object>> data = tableService.getSgsDept(type);
			result.setData(data);
			return result;
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("获取双公示部门异常，请稍后再试");
			return result;
		}

	}

	@IgnoreAuthority
	@RequestMapping(value = "/getListByTableId.json")
	public RestServiceResult<List<Map<String, Object>>> getListByTableId(
			@RequestParam(value = "tableId", defaultValue = "", required = true) String tableId,
			@RequestParam(value = "xmmc", defaultValue = "", required = true) String xmmc,
			@RequestParam(value = "deptId", defaultValue = "", required = true) List<String> deptId, Page page) {
		RestServiceResult<List<Map<String, Object>>> result = new RestServiceResult<List<Map<String, Object>>>();
		try {
			List<Map<String, Object>> data = tableService.getListByTableIdForPage(xmmc, tableId, deptId, page);
			result.setData(data);
			result.setCount(page.getTotalCount());
			return result;
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("获取数据异常，请稍后再试");
			return result;
		}

	}

	@IgnoreAuthority
	@RequestMapping(value = "/exportListByTableId.json")
	public RestServiceResult<List<Map<String, Object>>> exportListByTableId(
			@RequestParam(value = "xmmc", defaultValue = "", required = true) String xmmc,
			@RequestParam(value = "tableId", defaultValue = "", required = true) String tableId,
			@RequestParam(value = "deptId", defaultValue = "", required = true) List<String> deptId,
			HttpServletResponse response, Page page) {
		page.setLimit(1000);
		String type = "";
		RestServiceResult<List<Map<String, Object>>> result = new RestServiceResult<List<Map<String, Object>>>();
		try {
			if (tableId.equals("210102")) {
				type = "行政许可目录统计";
			} else if (tableId.equals("210106")) {
				type = "行政处罚目录统计";
			}
			List<Map<String, Object>> data = tableService.getListByTableIdForPage(xmmc, tableId, deptId, page);
			List<String> showColumns = new ArrayList<String>();

			showColumns.add("OFFICE_NAME");
			showColumns.add("count");

			List<OptionalColumn> OptionalColumns = new ArrayList<>();
			OptionalColumn optionalColumn = new OptionalColumn("OFFICE_NAME", "行政决定部门", "varchar", true, "input", false,
					new HashMap<String, String>(), false);
			OptionalColumns.add(optionalColumn);

			optionalColumn = new OptionalColumn("count", "事项数量", "number", true, "input", false,
					new HashMap<String, String>(), false);
			OptionalColumns.add(optionalColumn);

			ExcelUtil.downloadExcel(response, data, type, type, showColumns, OptionalColumns);
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("下载数据异常，请稍后再试");
			return result;
		}
		return result;

	}

	@IgnoreAuthority
	@RequestMapping(value = "/getDeptByTableId.json")
	public RestServiceResult<List<Map<String, Object>>> getDeptByTableId(String tableId) {
		RestServiceResult<List<Map<String, Object>>> result = new RestServiceResult<List<Map<String, Object>>>();
		try {
			List<Map<String, Object>> data = tableService.getDeptByTableId(tableId);
			result.setData(data);
			return result;
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("获取部门异常，请稍后再试");
			return result;
		}

	}

	/**
	 * 行政资源下载
	 */

	@IgnoreAuthority
	@RequestMapping(value = "/getSgsDataList.json")
	public RestServiceResult<List<Map<String, Object>>> getSgsDataList(
			@RequestParam(value = "condition", defaultValue = "", required = true) String condition,
			@RequestParam(value = "columnEN", defaultValue = "", required = true) String columnEN,
			@RequestParam(value = "type", defaultValue = "", required = true) String type,
			@RequestParam(value = "startTime", defaultValue = "", required = true) String startTime,
			@RequestParam(value = "endTime", defaultValue = "", required = true) String endTime,
			@RequestParam(value = "jdrqStart", defaultValue = "", required = true) String jdrqStart,
			@RequestParam(value = "jdrqEnd", defaultValue = "", required = true) String jdrqEnd,
			@RequestParam(value = "deptId", defaultValue = "", required = true) List<String> deptId, Page page,
			HttpServletResponse response) {
		RestServiceResult<List<Map<String, Object>>> result = new RestServiceResult<List<Map<String, Object>>>();
		String[] configColumns = null;

		List<String> columns = java.util.Arrays.asList(columnEN.split(","));
		try {

			List<Map<String, Object>> data = tableService.getSgsDataListByConditionForPage(null, columns,
					new String[] { "md5" }, condition, page, type, deptId, startTime, endTime, jdrqStart, jdrqEnd);

			result.setData(data);
			result.setCount(page.getTotalCount());
		} catch (Exception e) {
			ExceptionLogger.error("ResouceSearchController#getSgsDataList", "查询下载列表异常，请稍后再试！ERROR:" + e.getMessage(),
					e);
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("查询下载列表异常，请稍后再试");
			return result;
		}

		return result;
	}

	@IgnoreAuthority
	@RequestMapping(value = "/getSgsDataOptionalColumns.json")
	public RestServiceResult<List<OptionalColumn>> getSgsDataOptionalColumns(
			@RequestParam(value = "type", defaultValue = "", required = true) String type) {

		RestServiceResult<List<OptionalColumn>> result = new RestServiceResult<List<OptionalColumn>>();
		List<OptionalColumn> optionalColumnByTableId = new ArrayList<OptionalColumn>();
		try {

			if ("许可".equals(type)) {
				optionalColumnByTableId = SgsXkExportEnum.getOptionalColumns("XK");

			} else {
				optionalColumnByTableId = SgsCfExportEnum.getOptionalColumns("CF");
			}
			result.setData(optionalColumnByTableId);
			return result;
		} catch (Exception e) {
			ExceptionLogger.error("ResouceSearchController#getSgsOptionalColumns", "系统异常稍后再试！ERROR:" + e.getMessage(),
					e);
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("系统异常请稍后再试");
			return result;
		}
	}

	/**
	 * 行政资源下载
	 */

	@IgnoreAuthority
	@RequestMapping(value = "/exportSgsData.json")
	public RestServiceResult<List<Map<String, Object>>> exportSgsData(
			@RequestParam(value = "condition", defaultValue = "", required = true) String condition,
			@RequestParam(value = "columnEN", defaultValue = "", required = true) String columnEN,
			@RequestParam(value = "type", defaultValue = "", required = true) String type,
			@RequestParam(value = "startTime", defaultValue = "", required = true) String startTime,
			@RequestParam(value = "endTime", defaultValue = "", required = true) String endTime,
			@RequestParam(value = "jdrqStart", defaultValue = "", required = true) String jdrqStart,
			@RequestParam(value = "jdrqEnd", defaultValue = "", required = true) String jdrqEnd,
			@RequestParam(value = "deptId", defaultValue = "", required = true) List<String> deptId,
			@RequestParam(value = "recordIds", defaultValue = "", required = true) List<String> recordIds, Page page,
			HttpServletResponse response) {
		RestServiceResult<List<Map<String, Object>>> result = new RestServiceResult<List<Map<String, Object>>>();
		String[] configColumns = null;
		List<String> columns = java.util.Arrays.asList(columnEN.split(","));
		try {

			List<Map<String, Object>> data = tableService.getSgsDataListByCondition(recordIds, columns, new String[] {},
					condition, type, deptId, startTime, endTime, jdrqStart, jdrqEnd);
			result.setCount(page.getTotalCount());
			result.setData(data);
			if (type.equals("许可")) {
				ExcelUtil.downloadExcel(response, data, type, type, columns, SgsXkExportEnum.getOptionalColumns("XK"));

			} else {
				ExcelUtil.downloadExcel(response, data, type, type, columns, SgsCfExportEnum.getOptionalColumns("CF"));

			}

		} catch (Exception e) {
			ExceptionLogger.error("ResouceSearchController#getSgsDataList", "查询下载列表异常，请稍后再试！ERROR:" + e.getMessage(),
					e);
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("查询下载列表异常，请稍后再试");
			return result;
		}

		return result;
	}

	@IgnoreAuthority
	@RequestMapping(value = "/getDataByTableId.json")
	public RestServiceResult<List<Map<String, Object>>> getDataByTableId(
			@RequestParam(value = "tableId", defaultValue = "", required = true) String tableId,
			@RequestParam(value = "xmmc", defaultValue = "", required = true) String xmmc,
			@RequestParam(value = "xzxdrlb", defaultValue = "", required = true) String xzxdrlb,
			@RequestParam(value = "sdyj", defaultValue = "", required = true) String sdyj,
			@RequestParam(value = "deptId", defaultValue = "", required = true) List<String> deptId, Page page) {
		RestServiceResult<List<Map<String, Object>>> result = new RestServiceResult<List<Map<String, Object>>>();
		try {
			List<Map<String, Object>> data = tableService.getDataByTableIdForPage(xmmc, xzxdrlb, sdyj, tableId, deptId,
					page);
			result.setData(data);
			result.setCount(page.getTotalCount());
			return result;
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("获取数据异常，请稍后再试");
			return result;
		}

	}

	/**
	 * 其他统计
	 */

	@IgnoreAuthority
	@RequestMapping(value = "/getOtherTotalByTableId.json")
	public RestServiceResult<List<Map<String, Object>>> getOtherTotalByTableId(
			@RequestParam(value = "tableId", defaultValue = "", required = true) String tableId,
			@RequestParam(value = "condition", defaultValue = "", required = true) String condition,

			Page page) {
		RestServiceResult<List<Map<String, Object>>> result = new RestServiceResult<List<Map<String, Object>>>();
		try {
			List<Map<String, Object>> data = tableService.getOtherTotalByTableIdForPage(tableId, condition, page);
			result.setData(data);
			result.setCount(page.getTotalCount());
			return result;
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("获取数据异常，请稍后再试");
			return result;
		}

	}

	/**
	 * 导出其他统计
	 */

	@IgnoreAuthority
	@RequestMapping(value = "/exportOtherTotalByTableId.json")
	public RestServiceResult<List<Map<String, Object>>> exportOtherTotalByTableId(
			@RequestParam(value = "tableId", defaultValue = "", required = true) String tableId,
			@RequestParam(value = "tablename", defaultValue = "", required = true) String tablename,
			@RequestParam(value = "condition", defaultValue = "", required = true) String condition,
			HttpServletResponse response, Page page) {
		RestServiceResult<List<Map<String, Object>>> result = new RestServiceResult<List<Map<String, Object>>>();
		try {
			page.setLimit(50000);
			List<Map<String, Object>> data = tableService.getOtherTotalByTableIdForPage(tableId, condition, page);
			List<String> showColumns = new ArrayList<String>();

			showColumns.add("ztmc");
			showColumns.add("count");

			List<OptionalColumn> OptionalColumns = new ArrayList<>();
			OptionalColumn optionalColumn = new OptionalColumn("ztmc", "主体名称", "varchar", true, "input", false,
					new HashMap<String, String>(), false);
			OptionalColumns.add(optionalColumn);

			optionalColumn = new OptionalColumn("count", "发生次数", "number", true, "input", false,
					new HashMap<String, String>(), false);
			OptionalColumns.add(optionalColumn);

			ExcelUtil.downloadExcel(response, data, tablename, tablename, showColumns, OptionalColumns);
			return result;
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("导出数据异常，请稍后再试");
			return result;
		}

	}

	/**
	 * 双公示台账
	 */

	@IgnoreAuthority
	@RequestMapping(value = "/getSgstzList.json")
	public RestServiceResult<List<Map<String, Object>>> getSgstzList(
			@RequestParam(value = "wsh", defaultValue = "", required = true) String wsh,
			@RequestParam(value = "xzxdrmc", defaultValue = "", required = true) String xzxdrmc,
			@RequestParam(value = "type", defaultValue = "", required = true) String type,
			@RequestParam(value = "startTime", defaultValue = "", required = true) String startTime,
			@RequestParam(value = "endTime", defaultValue = "", required = true) String endTime,
			@RequestParam(value = "jdrqStart", defaultValue = "", required = true) String jdrqStart,
			@RequestParam(value = "jdrqEnd", defaultValue = "", required = true) String jdrqEnd,
			@RequestParam(value = "deptId", defaultValue = "", required = true) List<String> deptId, Page page,
			HttpServletResponse response) {
		RestServiceResult<List<Map<String, Object>>> result = new RestServiceResult<List<Map<String, Object>>>();

		try {

			List<Map<String, Object>> data = tableService.getSgstzListForPage(page, type, deptId, startTime, endTime,
					jdrqStart, jdrqEnd, wsh, xzxdrmc, null);
			result.setCount(page.getTotalCount());
			result.setData(data);

		} catch (Exception e) {
			ExceptionLogger.error("ResouceSearchController#getSgstzListForPage",
					"查询双公示异常，请稍后再试！ERROR:" + e.getMessage(), e);
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("查询双公示异常，请稍后再试");
			return result;
		}

		return result;
	}

	/**
	 * 导出双公示台账
	 */

	@IgnoreAuthority
	@RequestMapping(value = "/exportSgstzList.json")
	public RestServiceResult<List<Map<String, Object>>> exportSgstzList(
			@RequestParam(value = "wsh", defaultValue = "", required = true) String wsh,
			@RequestParam(value = "xzxdrmc", defaultValue = "", required = true) String xzxdrmc,
			@RequestParam(value = "type", defaultValue = "", required = true) String type,
			@RequestParam(value = "startTime", defaultValue = "", required = true) String startTime,
			@RequestParam(value = "endTime", defaultValue = "", required = true) String endTime,
			@RequestParam(value = "jdrqStart", defaultValue = "", required = true) String jdrqStart,
			@RequestParam(value = "jdrqEnd", defaultValue = "", required = true) String jdrqEnd,
			@RequestParam(value = "deptId", defaultValue = "", required = true) List<String> deptId,
			@RequestParam(value = "recordIds", defaultValue = "", required = true) List<String> recordIds, Page page,
			HttpServletResponse response) {
		RestServiceResult<List<Map<String, Object>>> result = new RestServiceResult<List<Map<String, Object>>>();
		page.setLimit(100000);
		try {
			List<String> showColumns = new ArrayList<String>();

			showColumns.add("JDJG");
			showColumns.add("A000001");
			showColumns.add("A000002");
			showColumns.add("WSH");
			showColumns.add("JDRQ");
			showColumns.add("sfdsSzb");
			showColumns.add("sfzcgs");
			showColumns.add("bz");
			List<Map<String, Object>> data = tableService.getSgstzList(page, type, deptId, startTime, endTime,
					jdrqStart, jdrqEnd, wsh, xzxdrmc, recordIds);
			List<OptionalColumn> OptionalColumns = new ArrayList<>();

			OptionalColumn optionalColumn = new OptionalColumn("JDJG", "行政决定部门", "varchar", true, "input", false,
					new HashMap<String, String>(), false);
			OptionalColumns.add(optionalColumn);
			optionalColumn = new OptionalColumn("A000001", "行政相对人名称/项目名称", "varchar", true, "input", false,
					new HashMap<String, String>(), false);
			OptionalColumns.add(optionalColumn);
			optionalColumn = new OptionalColumn("A000002", "统一社会信用代码", "varchar", true, "input", false,
					new HashMap<String, String>(), false);
			OptionalColumns.add(optionalColumn);
			if (type.equals("xzxk")) {
				type = "行政许可";
				optionalColumn = new OptionalColumn("WSH", "行政许可决定书文号", "varchar", true, "input", false,
						new HashMap<String, String>(), false);
				OptionalColumns.add(optionalColumn);
			} else {
				type = "行政处罚";

				optionalColumn = new OptionalColumn("WSH", "行政处罚决定书文号", "varchar", true, "input", false,
						new HashMap<String, String>(), false);
				OptionalColumns.add(optionalColumn);
			}
			optionalColumn = new OptionalColumn("JDRQ", "行政决定日期", "varchar", true, "input", false,
					new HashMap<String, String>(), false);
			OptionalColumns.add(optionalColumn);

			optionalColumn = new OptionalColumn("sfdsSzb", "是否向“信用中国(北京)”推送", "varchar", true, "select", false,
					new HashMap<String, String>() {
						private static final long serialVersionUID = 519309474876999409L;
						{
							put("Y", "是");
							put("N", "否");
						}
					}, true);
			OptionalColumns.add(optionalColumn);
			optionalColumn = new OptionalColumn("sfzcgs", "是否在七个工作日内公司", "varchar", true, "select", false,
					new HashMap<String, String>() {
						private static final long serialVersionUID = 519309474876999409L;
						{
							put("1", "是");
							put("0", "否");
						}
					}, false);
			OptionalColumns.add(optionalColumn);

			optionalColumn = new OptionalColumn("bz", "备注", "number", true, "input", false,
					new HashMap<String, String>(), false);
			OptionalColumns.add(optionalColumn);

			ExcelUtil.downloadExcel(response, data, type, type, showColumns, OptionalColumns);

		} catch (Exception e) {
			ExceptionLogger.error("ResouceSearchController#exportSgstzListForPage",
					"导出双公示异常，请稍后再试！ERROR:" + e.getMessage(), e);
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("导出双公示异常，请稍后再试");
			return result;
		}

		return result;
	}

	/**
	 * 双公示迟报率
	 */

	@IgnoreAuthority
	@RequestMapping(value = "/getSgsCblList.json")
	public RestServiceResult<List<Map<String, Object>>> getSgsCblList(

			@RequestParam(value = "type", defaultValue = "", required = true) String type,
			@RequestParam(value = "startTime", defaultValue = "", required = true) String startTime,
			@RequestParam(value = "endTime", defaultValue = "", required = true) String endTime,

			@RequestParam(value = "deptId", defaultValue = "", required = true) List<String> deptId, Page page,
			HttpServletResponse response) {
		RestServiceResult<List<Map<String, Object>>> result = new RestServiceResult<List<Map<String, Object>>>();

		try {

			List<Map<String, Object>> data = tableService.getSgsCblListForPage(page, type, deptId, startTime, endTime);
			result.setCount(page.getTotalCount());
			result.setData(data);

		} catch (Exception e) {
			ExceptionLogger.error("ResouceSearchController#getSgsCblListForPage",
					"查询双公示迟报率异常，请稍后再试！ERROR:" + e.getMessage(), e);
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("查询双公示迟报率异常，请稍后再试");
			return result;
		}

		return result;
	}

	/**
	 * 导出双公示迟报率
	 */

	@IgnoreAuthority
	@RequestMapping(value = "/exportSgsCblList.json")
	public RestServiceResult<List<Map<String, Object>>> exportSgsCblList(

			@RequestParam(value = "type", defaultValue = "", required = true) String type,
			@RequestParam(value = "startTime", defaultValue = "", required = true) String startTime,
			@RequestParam(value = "endTime", defaultValue = "", required = true) String endTime,

			@RequestParam(value = "deptId", defaultValue = "", required = true) List<String> deptId, Page page,
			HttpServletResponse response) {
		RestServiceResult<List<Map<String, Object>>> result = new RestServiceResult<List<Map<String, Object>>>();
		page.setLimit(500);
		try {
			List<String> showColumns = new ArrayList<String>();

			showColumns.add("deptName");
			showColumns.add("zs");
			showColumns.add("jssl");
			showColumns.add("cbl");

			List<Map<String, Object>> data = tableService.getSgsCblListForPage(page, type, deptId, startTime, endTime);
			List<OptionalColumn> OptionalColumns = new ArrayList<>();

			OptionalColumn optionalColumn = new OptionalColumn("deptName", "区属单位名称", "varchar", true, "input", false,
					new HashMap<String, String>(), false);
			OptionalColumns.add(optionalColumn);
			optionalColumn = new OptionalColumn("jssl", "及时上报数量", "varchar", true, "input", false,
					new HashMap<String, String>(), false);
			OptionalColumns.add(optionalColumn);
			if (type.equals("xzxk")) {
				type = "行政许可";
				optionalColumn = new OptionalColumn("zs", "许可总数", "varchar", true, "input", false,
						new HashMap<String, String>(), false);
				OptionalColumns.add(optionalColumn);
				optionalColumn = new OptionalColumn("cbl", "许可迟报率", "varchar", true, "input", false,
						new HashMap<String, String>(), false);
				OptionalColumns.add(optionalColumn);
			} else {
				type = "行政处罚";

				optionalColumn = new OptionalColumn("zs", "处罚总数", "varchar", true, "input", false,
						new HashMap<String, String>(), false);
				OptionalColumns.add(optionalColumn);
				optionalColumn = new OptionalColumn("cbl", "处罚迟报率", "varchar", true, "input", false,
						new HashMap<String, String>(), false);
				OptionalColumns.add(optionalColumn);
			}
			ExcelUtil.downloadExcel(response, data, type, type, showColumns, OptionalColumns);

		} catch (Exception e) {
			ExceptionLogger.error("ResouceSearchController#exportSgsCblList",
					"导出双公示迟报率异常，请稍后再试！ERROR:" + e.getMessage(), e);
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("导出双公示迟报率异常，请稍后再试");
			return result;
		}

		return result;
	}
	

	/**
	 * @api {get} /resourceSearch/getTableList.json 资源列表
	 * @apiName getTableList
	 * @apiVersion 0.0.1
	 * @apiGroup 信息资源查询
	 * @apiParam {String} kId 数据库id (必需)
	 * @apiParam {String} condition 搜索条件 (可选)
	 * @apiParam {int} limit 每页展示条数 (必需)
	 * @apiParam {int} page 当前页数 (必需)
	 * @apiParamExample {json} 请求参数示例
	 *                  {"kId":"100000","limit":10,"page":1,"deptId":1,"condition":[{"colNameCN":"信息资源名称","colNameEN":"resource_title","type":"varchar","fuzzy":true,"value":"欠缴电费信息"},{"colNameCN":"维护时间","colNameEN":"update_time","type":"timestamp","fuzzy":false,"value":["2018-05-28","2018-06-26"]}]}
	 * @apiSuccess {String} code 状态码:1 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {Object[]} data 结果集
	 * @apiSuccessExample {json}成功返回结果:
	 *                    {"code":0,"msg":null,"count":1,"data":[{"tableId":200249,"deptId":1,"kId":100000,"resource_id":"10000060873","resource_title":"欠缴电费信息","sharing_type":"P","update_frequency":"W","management_style":"A","maintainer":"superadmin","update_time":1523844712000}]}
	 */

	@RequestMapping(value = "/getLyTableList.json")
	public RestServiceResult<List<Map<String, Object>>> getLyTableList(
			@RequestParam(value = "kId", defaultValue = "", required = true) String kId,
			@RequestParam(value = "deptId", defaultValue = "", required = true) String deptId,
			@RequestParam(value = "condition", defaultValue = "", required = true) String condition, Page page,
			HttpServletRequest request) {

		RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));

		String[] configColumns = null;

		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {

			SysUser userInfo = user.getData();

			if (null != userInfo) {

				configColumns = (String[]) MapCache.get(userInfo.getId() + "_" + FRONT_TABLE_ID);
			} else {

				ExceptionLogger.error("ResouceSearchController#getLyTableList", "未获取到当前用户信息！");
			}

		} else {

			ExceptionLogger.error("ResouceSearchController#getLyTableList", "未获取到当前用户信息！");
		}

		List<String> showColumns = (configColumns == null || configColumns.length == 0)
				? ResourceTableFieldsEnum.getDefaultShowColumnEN()
				: Arrays.asList(configColumns);

		String[] additionalColumns = { "tableId", "deptId", "kId" };

		List<Map<String, Object>> tableList = tableService.getLyTableListByConditionForPage(kId, deptId, "P", showColumns,
				additionalColumns, condition, page);

		return new RestServiceResult<List<Map<String, Object>>>(page.getTotalCount(), tableList);

	}
}
